// 笔试强训day32:活动安排

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct cmp
{
    // 结果为真时等号右边的上堆顶，second尽量小，first尽量大
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2)
    {
        if(p1.second > p2.second)
            return true;
        else if(p1.second == p2.second)
            return p1.first < p2.first;
        return false;
    }
};

int main() {
    int n, a, b; cin >> n;
    priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> q;
    while(n--)
    {
        cin >> a >> b;
        q.emplace(a, b);
    }

    int preEnd = 0, ans = 0;
    while(!q.empty())
    {
        pair<int, int> tmp = q.top();
        q.pop();
        if(tmp.first >= preEnd)
        {
            ans++;
            preEnd = tmp.second;
        }
    }
    cout << ans << endl;
}